package com.lzl.netty.server.handler;

import cn.hutool.core.date.DateUtil;
import com.lzl.netty.server.protobuf.MsgPro;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

import java.util.Date;

public class TimeServerHandler extends ChannelHandlerAdapter {


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg!=null){
            MsgPro.UserMsg userMsg=(MsgPro.UserMsg)msg;
            System.out.println(userMsg.getMsg());
        }

        MsgPro.UserMsg.Builder builder = MsgPro.UserMsg.newBuilder();
        builder.setMsg(DateUtil.formatDateTime(new Date()));
        builder.setMethodType("2");
        builder.setVersion("3");
        builder.setProCode("4");

        ctx.writeAndFlush(builder);
    }



}
